#include <stdio.h>

struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
};

// 前序遍历
void preOrder(struct TreeNode *root) {
    // 最小子问题
    if (root == NULL) return;
    // 遍历打印根节点
    printf("%d\n", root->val);
    // 遍历左子树
    preOrder(root->left);
    // 遍历右子树
    preOrder(root->right);
}

// 中序遍历
void inOrder(struct TreeNode *root) {
    // 最小子问题
    if (root == NULL) return;
    // 遍历左子树
    inOrder(root->left);
    // 遍历打印根节点
    printf("%d\n", root->val);
    // 遍历右子树
    inOrder(root->right);
}

// 后序遍历
void postOrder(struct TreeNode *root) {
    // 最小子问题
    if (root == NULL) return;
    // 遍历左子树
    postOrder(root->left);
    // 遍历右子树
    postOrder(root->right);
    // 遍历打印根节点
    printf("%d\n", root->val);
}

int main(void) {
    struct TreeNode node5 = {7, NULL, NULL};
    struct TreeNode node4 = {11, NULL, NULL};
    struct TreeNode node3 = {23, NULL, NULL};
    struct TreeNode node2 = {9, NULL, &node5};
    struct TreeNode node1 = {8, &node3, &node4};
    struct TreeNode root = {10, &node1, &node2};

    postOrder(&root);

    return 0;
}
